package Windows.DownLoads;

import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;

import GroupWare.DownloadTask;
import Tools.IMG;
import Tools.JLabelStyle;
import Tools.Units;
import Windows.ShowWindows.ShowWindow;
import XML.XMLNode;

/**
 * 
 * @author __USER__
 */
public class ShowDownloadWindow extends ShowWindow implements MouseListener {

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				XMLNode xf = new XMLNode(null, "task");
				xf.put("State", "ok");
				xf.put("name", "QQ2009.EXE");
				xf.put("size", "52665959");
				xf.put("MD5", "DTGY789IO03FTGBNHJ");
//				ShowDownWindow xzw = new ShowDownWindow(xf);
//				xzw.start();
			}
		});
	}
	private JLabelStyle jlsAction = (JLabelStyle) JLabelStyle.getStyleListener();

	private DownloadTask df;

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JLabel jLabel2;

	private javax.swing.JLabel jLabel4;

	// GEN-END:initComponents

	private javax.swing.JLabel jLabel6;

	public javax.swing.JLabel jlClose;
	public javax.swing.JLabel jlMD5;
	public javax.swing.JLabel jlOpenDir;
	public javax.swing.JLabel jlOpenFile;
	public javax.swing.JLabel jlSize;
	public javax.swing.JLabel jlTitle;
	public javax.swing.JLabel jlname;
	/** Creates new form Xiazaiwancheng */
	public ShowDownloadWindow(DownloadTask df) {
		super(IMG.SHOW_BG);
		this.df = df;
		initComponents();
		setSize(241, 171);

		showTitle();
		jlname.setText(df.getXML().get("name"));
		jlSize.setText(Units.byteCondense(Long.parseLong(df.getXML().get("size"))));
		String md5 = df.getXML().FLAG;
		if (md5.length() < 16)
			md5 = df.getXML().get("md5");
		jlMD5.setText(md5.toUpperCase());

		JLabelStyle.setStyle(jLabel2);
		JLabelStyle.setStyle(jLabel4);
		JLabelStyle.setStyle(jLabel6);
		JLabelStyle.setStyle(jlClose);
		JLabelStyle.setStyle(jlMD5);
		JLabelStyle.setStyle(jlOpenDir);
		JLabelStyle.setStyle(jlOpenFile);
		JLabelStyle.setStyle(jlSize);
		JLabelStyle.setStyle(jlTitle);
		JLabelStyle.setStyle(jlname);
	}
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jlTitle = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jlname = new javax.swing.JLabel();
		jLabel4 = new javax.swing.JLabel();
		jlSize = new javax.swing.JLabel();
		jLabel6 = new javax.swing.JLabel();
		jlMD5 = new javax.swing.JLabel();
		jlOpenFile = new javax.swing.JLabel();
		jlClose = new javax.swing.JLabel();
		jlOpenDir = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("任务状态");

		jlTitle.setFont(new Font("宋体", Font.BOLD, 14));
		jlTitle.setText("\u5df2\u4e0b\u8f7d\u5b8c\u6210");
		// jlTitle.setFont(new Font());
		jLabel2.setText("\u6587\u4ef6\u540d\uff1a");

		jlname.setText("ssssssssssssssssssssss");

		jLabel4.setText("\u6587\u4ef6\u5927\u5c0f\uff1a");

		jlSize.setText("yyyyyyyyyyyyyyyyyyyyyy");

		jLabel6.setText("MD5\uff1a");

		jlMD5.setText("zzzzzzzzzzzzzzzzzzzzzzz");

		jlOpenFile.setText("\u6253\u5f00\u6587\u4ef6");

		jlOpenFile.addMouseListener(jlsAction);
		jlOpenDir.addMouseListener(jlsAction);
		jlClose.addMouseListener(jlsAction);

		jlClose.setText("\u5173\u95ed");
		jlClose.addMouseListener(this);
		jlOpenFile.addMouseListener(this);
		jlOpenDir.addMouseListener(this);
		jlOpenDir.setText("\u6253\u5f00\u6587\u4ef6\u5939");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addGap(32, 32, 32).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel6).addComponent(jLabel2).addComponent(jLabel4).addComponent(jlOpenFile, javax.swing.GroupLayout.Alignment.LEADING)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(jlMD5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jlSize, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jlname, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jlTitle)).addGroup(layout.createSequentialGroup().addComponent(jlOpenDir).addGap(18, 18, 18).addComponent(jlClose))).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addGap(20, 20, 20).addComponent(jlTitle).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(jlname)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4).addComponent(jlSize)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel6).addComponent(jlMD5)).addGap(36, 36, 36)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jlOpenDir).addComponent(jlClose).addComponent(jlOpenFile, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	@Override
	public void mouseClicked(MouseEvent me) {
		// TODO Auto-generated method stub
		Close();
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		this.exists = -1;
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		this.exists = 0;
	}

	@Override
	public void mousePressed(MouseEvent me) {
		// TODO Auto-generated method stub
		// this.setVisible(false);
		Object obj = me.getSource();
		if (obj.getClass() == JLabel.class) {
			JLabel jl = (JLabel) obj;
			System.out.println(jl);
			if (jl == jlOpenFile) {
				df.open();
				System.out.println("OPen:" + df);
			} else if (jl == jlOpenDir) {
				df.openDir();
				System.out.println("OPenDir:" + df);
			}
		}

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		// 关闭效果下滑，不直接消失。
	}

	public void showTitle() {
		String str = df.getXML().get("State").toLowerCase();
		if (str.equals("new")) {
			str = "创建任务";
			jlOpenFile.setEnabled(false);
		} else if (str.equals("ok")) {
			str = "完成任务";
			jlOpenFile.setEnabled(true);
		}
		jlTitle.setText(str);
	}

	// End of variables declaration//GEN-END:variables

}